package br.com.consultsystems.dominio.cadastro;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import br.com.consultsystems.dominio.tipos.EstadoCivil;

@Entity
@Table(name = "pessoa")
@SequenceGenerator(name = "operacao", sequenceName = "operacao",  allocationSize = 1)
@XmlRootElement
public class Pessoa implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2039801289566978780L;

	@Id
	@Column(name = "id", nullable = false, insertable = true, updatable = false)
	@GeneratedValue(generator = "operacao", strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Column(name = "nome", nullable = false, insertable = true, updatable = true, length = 200)
	private String nome;

	@Column(name = "cpf", nullable = false, insertable = true, updatable = true, unique = true, length = 14)
	private String cpf;

	@Column(name = "rg", nullable = true, insertable = true, updatable = true, length = 18)
	private String rg;

	@Column(name = "datacadastro", nullable = false, insertable = true, updatable = false)
	@Temporal(TemporalType.DATE)
	private Date dataCadastro;

	@Column(name = "estadocivil", nullable = true, insertable = true, updatable = true, length = 20)
	@Enumerated(EnumType.STRING)
	private EstadoCivil estadoCivil;
	
	@Column(name = "email", nullable = true, insertable = true, updatable = true, length = 18)
	private String email;

	@Column(name = "telefone", nullable = true, insertable = true, updatable = true, length = 18)
	private String telefone;

	@Column(name = "celular", nullable = true, insertable = true, updatable = true, length = 18)
	private String celular;
	
	public Pessoa() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getCpf() {
		return cpf;
	}

	public void setCpf(String cpf) {
		this.cpf = cpf;
	}

	public String getRg() {
		return rg;
	}

	public void setRg(String rg) {
		this.rg = rg;
	}

	public Date getDataCadastro() {
		return dataCadastro;
	}

	public void setDataCadastro(Date dataCadastro) {
		this.dataCadastro = dataCadastro;
	}

	public EstadoCivil getEstadoCivil() {
		return estadoCivil;
	}

	public void setEstadoCivil(EstadoCivil estadoCivil) {
		this.estadoCivil = estadoCivil;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getTelefone() {
		return telefone;
	}

	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}

	public String getCelular() {
		return celular;
	}

	public void setCelular(String celular) {
		this.celular = celular;
	}

	@Override
	public String toString() {
		return "Pessoa [id=" + id + ", nome=" + nome + ", cpf=" + cpf
				+ ", rg=" + rg + ", dataCadastro=" + dataCadastro
				+ ", estadoCivil=" + estadoCivil + ", email=" + email
				+ ", telefone=" + telefone + ", celular=" + celular + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pessoa other = (Pessoa) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
}
